package cn.dujc.superkid.activities;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import cn.dujc.core.ui.BaseActivity;
import cn.dujc.core.util.ToastUtil;
import cn.dujc.superkid.R;
import cn.dujc.superkid.api.HttpHelper;
import cn.dujc.superkid.api.QMap;
import cn.dujc.superkid.api.Result;
import cn.dujc.superkid.api.ResultCallBack;
import cn.dujc.superkid.bean.RegisterResult;
import cn.dujc.superkid.utils.Preferences;

/**
 * Created by Administrator on 2018/10/23 0023.
 */

public class ExamMessage extends BaseActivity {
    EditText editText;
    Button submitView;
    private String examine_id;

    @Override
    public int getViewId() {
        return R.layout.activity_leaving;
    }

    @Override
    public void initBasic(Bundle savedInstanceState) {
        examine_id=getIntent().getStringExtra("examine_id");
        editText = findViewById(R.id.leaving_edit);
        submitView = findViewById(R.id.leaving_submit);
        submitView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                leaving();
            }
        });
    }

    private void leaving() {
        String text = editText.getText().toString();
        if (TextUtils.isEmpty(text)) {
            ToastUtil.showToast(this, "请输入留言");
            return;
        }
        submitMessage();
    }
    private void submitMessage() {
        final RegisterResult loginResult = Preferences.getInstance().getLoginResult(mActivity);
        HttpHelper.getCourse().message(QMap.build()
                .put("user_id", loginResult.getUid())
                .put("channel", Preferences.getInstance().getChannel(mActivity).getChannel_id())
                .put("examine_id", Integer.parseInt(examine_id))
                .put("logincode", loginResult.getLogincode())
                .put("type_id", 2)
                .put("content", editText.getText().toString())
                .create()).enqueue(new ResultCallBack<Result<Object>>(mActivity) {
            @Override
            public void onSuccessCallback(int code, Result<Object> body) {
                ToastUtil.showToast(mActivity,body.getMsg());
                setResult(RESULT_OK);
                finish();
            }
        });
    }
}
